package business;

import java.util.List;

import models.User;
import models.forms.LoginForm;
import models.forms.SignupForm;
import dao.UserDao;
import dao.impl.UserDaoImpl;

public class UserBusiness {
	private UserDao userDao;

	public UserBusiness() {
		this.userDao = new UserDaoImpl();
	}

	public boolean checkExistByUsername(String username) {
		return this.userDao.checkExistByUsername(username);
	}

	public void save(SignupForm form) {
		User user = new User();
		user.setUsername(form.getUsername());
		user.setPassword(form.getPassword());
		user.setFullName(form.getFullName());
		user.setGender(form.getGender());
		userDao.insert(user);
	}
	
	public User login(LoginForm form){
		System.out.println("Username: "+form.getUsername()+", password: "+form.getPassword());
		return userDao.selectByUsernameAndPassword(form.getUsername(), form.getPassword());
	}
	
	public List<User> selectAll(){
		return userDao.selectAll();
	}
}
